package com.example.javaproject.okhttp;


import com.example.javaproject.spider.FigTxt;
import com.example.javaproject.spider.SpiderImageDownloader;

import java.io.File;

/**
 * 下载指定的图文
 */
public class SpiderMomentDownloader implements Runnable {
    FigTxt moment;

    public SpiderMomentDownloader(FigTxt userTrack) {
        this.moment = userTrack;
    }

    @Override
    public void run() {
        if (moment == null || moment.picUrls == null || moment.picUrls.size() == 0 || moment.isLike == 0)
            return;
        // YHouseApplication.getInstance().getExternalFilesDir(Environment.DIRECTORY_PICTURES);
        System.out.println("start download:" + moment.userName + " 's " + moment.title);
        File externalFilesDir = new File("E:\\images");
        File momentDir = new File(externalFilesDir, moment.userName + File.separatorChar + moment.id);
        momentDir.mkdirs();
        for (String imageUrl : moment.picUrls) {
            if (TextUtils.isEmpty(imageUrl)) continue;
            PriorityThreadPool.getInstance().execute(new SpiderImageDownloader(imageUrl, momentDir));
        }
    }
}
